package com.dreamlyn.sharding;

import com.dreamlyn.sharding.entity.TOrder;
import com.dreamlyn.sharding.mapper.TOrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Slf4j
@Configuration
public class UseShardingDatasource implements ApplicationRunner {

    @Autowired
    private TOrderMapper TOrderMapper;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        TOrder tOrder = new TOrder();
        tOrder.setUserId(0L);
        tOrder.setDescr("测试");
        TOrderMapper.insert(tOrder);
        TOrderMapper.insert(tOrder);
        TOrderMapper.insert(tOrder);
        TOrderMapper.insert(tOrder);
        TOrderMapper.insert(tOrder);

        //设置数据源
        List<TOrder> TOrders = TOrderMapper.selectList(null);
        log.info("orders:{}", TOrders);


    }
}